<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.pearlsoft.rms.RmsHelper"%>
<%
String orgName=request.getParameter("org");
String vdcName=request.getParameter("vdc");
String appName=request.getParameter("app");
String vmName=request.getParameter("vm");

String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String ticket=RmsHelper.acquireTicket(orgName,vdcName,appName,vmName);
%>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>VM Console</title>

        <link href="../../../js/vmrc/jquery-ui/jquery-ui-1.8.13.custom.css" rel="stylesheet" type="text/css" />
        <link href="../../../css/console.css" rel="stylesheet" type="text/css" />
        <link href="../../../css/jquery-custom.css" rel="stylesheet" type="text/css" />

        <script type="text/javascript" src="../../../js/vmrc/jquery/jquery-1.6.1.min.js"></script>
        <script type="text/javascript" src="../../../js/vmrc/jquery-ui/jquery-ui-1.8.13.custom.min.js"></script>
        <script type="text/javascript" src="../../../js/vmrc/core.js"></script>
        <script type="text/javascript" src="../../../js/vmrc/debug.js"></script>
        <script type="text/javascript" src="../../../js/vmrc/event-manager.js"></script>
        <script type="text/javascript" src="../../../js/vmrc/button.js"></script>
        <script type="text/javascript" src="../../../js/vmrc/button-manager.js"></script>
        <script type="text/javascript" src="../../../js/vmrc/dialog.js"></script>
        <script type="text/javascript" src="../../../js/vmrc/dialog-manager.js"></script>
        <script type="text/javascript" src="../../../js/vmrc/alert.js"></script>
        <script type="text/javascript" src="../../../js/vmrc/confirm.js"></script>
        <script type="text/javascript" src="../../../js/vmrc/constants.js"></script>
        <script type="text/javascript" src="../../../js/vmrc/normalize-constants.js"></script>
        <script type="text/javascript" src="../../../js/vmrc/parse-ticket.js"></script>
        <script type="text/javascript" src="../../../js/vmrc/console.js"></script>
        <script type="text/javascript" src="../../../js/vmrc/vcd-console.js"></script>
        <script type="text/javascript">
            /**
             * Retrieve the ticket from the query string of the page URL.
             *
             * In practice, the ticket passing would involve a more complex mechanism.
             * This method is not robust and does not allow users to refresh the page.
             *
             * Additionally, this method violates the intent of the ticketer function;
             * a unique/new ticket should be returned each time. Howere, to avoid
             * assumptions about backend technologies being used, this is not shown
             * in this example. For a client to be compatible with updates to the API,
             * it would need to obey that contract.
             *
             * @return {string} A ticket URI.
             */
            var getTicket = function () {
                return '<%=ticket%>';
            }

            $(function() {
                vmware.log("TRACE", "init", "Ticket: {0}".format(getTicket()));

                $('#footer').text("Connecting...".localize());
                console1 = vmware.vcdConsole("mainContent", "toolbar", "footer");
                var ticket=getTicket();
                if(ticket==''||ticket=='null') {
                    alert('主机处于关闭状态或连接超时');
                } else {
                  console1.init(getTicket);
                }
            });
        </script>
    </head>
    <body>
        <div id="toolbar"></div>
        <div id="mainContent"></div>
        <div id="footer"></div>
    </body>
</html>
